#ifndef MATERIALLIST_H
#define MATERIALLIST_H

#include <QListView>
#include <QStyledItemDelegate>
#include <QPainter>
#include <QTouchEvent>
#include "material.h"

enum CustomRoles {
    MaterialId = Qt::UserRole + 1,
    VailCount,
    SaveType,
};

// ********************* MaterialListModel *************************/
class MaterialListModel : public QAbstractListModel {
    Q_OBJECT
public:
    explicit MaterialListModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

private:
    void setupConnections();

private:
    QVector<Material*> materials;

private slots:
    void LoadItems();
};

// ********************* MaterialListDelegate *************************/

class MaterialListDelegate : public QStyledItemDelegate {
public:
    explicit MaterialListDelegate(QListView *parent = nullptr)
        : QStyledItemDelegate(parent) {};

public:
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override;

};


// ********************* MaterialList *************************/
class MaterialList : public QListView
{
    Q_OBJECT
public:
    explicit MaterialList(QWidget *parent = nullptr);

private:
    void setupConnections();

private:
    MaterialListModel model;
    MaterialListDelegate* delegate;
    qint64 firstTouchTime;
    QPointF firstTouchPos;
    qint64 lastClickTime;

protected:
    bool eventFilter(QObject *obj, QEvent *event);

private slots:
    void itemClicked(const QModelIndex &index);
};
#endif // MATERIALLIST_H
